<template>
  <div class="mod-config">
    <div v-if="category">
      <div>
        <el-button type="primary" @click="showInfo()" style="margin-bottom: 20px;">新增</el-button>
      </div>
      <el-table :data="dataList" border v-loading="dataListLoading" style="width: 100%;">
        <el-table-column prop="bookName" header-align="center" align="center" label="课程类目"></el-table-column>
        <el-table-column prop="chapterNum" header-align="center" align="center" label="课程数"></el-table-column>
        <el-table-column header-align="center" align="center" label="结课人数">
          <template slot-scope="scope">
            {{scope.row.endClassNum || '—'}}
          </template>
        </el-table-column>
        <el-table-column header-align="center" align="center" label="课程列表 ">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="showCourse(scope.row.id)">查看</el-button>
          </template>
        </el-table-column>
        <el-table-column header-align="center" align="center" width="120" label="操作">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="showInfo(scope.row)">修改</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        :total="totalPage"
        layout="total, sizes, prev, pager, next, jumper"
      ></el-pagination>
    </div>
    <course-list v-else ref="courseList" @back = 'goback'></course-list>

    <audits-manage-add ref="auditsManageAdd" @refresh = 'getDataList'></audits-manage-add>
  </div>
</template>

<script>
  import AuditsManageAdd from "./update";
  import courseList from "../course/list";
  export default {
    data() {
      return {
        category: true,
        dataList: [],
        dataListLoading: false,
        dataForm: {},
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
      };
    },
    components: {
      AuditsManageAdd, courseList
    },
    mounted() {
      this.getDataList();
    },
    methods: {
      // 获取数据列表
      getDataList() {
        this.dataListLoading = true;
        let obj = {
          page: this.pageIndex,
          limit: this.pageSize,
        };
        this.$http({
          url: this.$http.adornUrl("/course/bookinfo/courseCategoryList"),
          method: "get",
          params: this.$http.adornParams(obj)
        }).then(({ data }) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list;
            this.totalPage = data.page.totalCount;
          } else {
            this.dataList = [];
            this.totalPage = 0;
          }
          this.dataListLoading = false;
        });
      },
      showCourse(id) {
        this.category = false
        this.$nextTick(() => {
          this.$refs.courseList.getDataList(id);
        })
      },
      goback() {
        this.category = true
      },
      showInfo(id) {
        this.$nextTick(() => {
          this.$refs.auditsManageAdd.initData(id);
        })
      },
      // 每页数
      sizeChangeHandle(val) {
        this.pageSize = val;
        this.pageIndex = 1;
        this.getDataList();
      },
      // 当前页
      currentChangeHandle(val) {
        this.pageIndex = val;
        this.getDataList();
      },
    }
  };
</script>
